import java.awt.Color;
import java.util.Random;

/**
 * A simple model of a fox.
 * Foxes age, move, eat rabbits, and die.
 * 
 * @author David J. Barnes and Michael Kolling
 * @version 2008.03.30
 */
public class Grass extends StaticEnvironment
{
    // Characteristics shared by all grass (static fields).
    
	private boolean eatable = true;
    private double eatAmount;
    private Location location;
    private double percentage = 0;
    private Color color = new Color(0, 105, 21);
    


    /**
     * Create a grass block. A fox can be created as a new born (age zero
     * and not hungry) or with a random age and food level.
     * 
     * @param randomAge If true, the fox will have random age and hunger level.
     * @param field The field currently occupied.
     * @param location The location within the field.
     */
    public Grass(boolean randomEatAmount, Field field, Location location, boolean isDeceased)
    {
        super(field, location);
        if(randomEatAmount) {
            eatAmount = new Random().nextInt(1000);
        }
        else {
            eatAmount = 5;
        }
        this.location = location;
    }
    
    /**
     * This is what the fox does most of the time: it hunts for
     * rabbits. In the process, it might breed, die of hunger,
     * or die of old age.
     * @param field The field currently occupied.
     * @param newFoxes A list to add newly born foxes to.
     */
    public void act()
    {
    	
    }
    
    public void lowerGrassAmount(Location l) { 
    	if(eatable) {
    		//lower the eatamount
    		eatAmount--;
    		//recalculate the per
    		percentage = (double)eatAmount * 0.1;
    		
    		calculatePercentageAndSetColor();
    		
    			if(eatAmount<=0) {
    				setDead();
    			}
    			
    	}
    	
    }
    
    /**
     * Get adjacent grassfield next to the rabbit and try to eat the grass
     * Call the act method from grass
     * @return counter
     */
    
    public boolean isEatable() {
		return eatable;
	}
    
    public Grass getGrass() { 
    	return this;
    }
    
    public Location getLocation()  {
    	return location;
    }
    
    public Color getColor() {
    	return color;
    }
    
    private void calculatePercentageAndSetColor() { 
    	if (percentage >= 0 && percentage <= 10) {
			color = new Color(0, 255, 51);
		} else if (percentage > 10 && percentage <= 20) {
			color = new Color(0, 240, 48);
		} else if (percentage > 20 && percentage <= 30) {
			color = new Color(0, 225, 45);
		} else if (percentage > 30 && percentage <= 40) {
			color = new Color(0, 210, 42);
		} else if (percentage > 40 && percentage <= 50) {
			color = new Color(0, 195, 39);
		} else if (percentage > 50 && percentage <= 60) {
			color = new Color(0, 180, 36);
		} else if (percentage > 60 && percentage <= 70) {
			color = new Color(0, 165, 33);
		} else if (percentage > 70 && percentage <= 80) {
			color = new Color(0, 150, 30);
		} else if (percentage > 80 && percentage <= 90) {
			color = new Color(0, 135, 27);
		} else if (percentage > 90 && percentage <= 95) {
			color = new Color(0, 120, 24);
		} else if (percentage > 95 && percentage <= 100) {
			color = new Color(0, 105, 21);
		}    			
    	
    	setColor(color);
    }
    
    public void setColor(Color color) {
    	this.color = (color);
    }
}
	

